package sveta.applogic1;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.ScreenshotException;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;

import sveta.util.PropertyLoader;
import sveta.util.Browser;
import sveta.webdriver.WebDriverFactory;
import sveta.applogic.*;




public class ApplicationManager1 implements ApplicationManager {
	private UserHelper userHelper;
	private FilmHelper filmHelper;
	private NavigationHelper navHelper;
	
	private WebDriver driver;
	private String baseUrl;
    private Browser browser;
    
    public ApplicationManager1(){
    	baseUrl = PropertyLoader.loadProperty("site.url");
		String gridHubUrl = PropertyLoader.loadProperty("grid2.hub");

		browser = new Browser();
		browser.setName(PropertyLoader.loadProperty("browser.name"));
		browser.setVersion(PropertyLoader.loadProperty("browser.version"));
		browser.setPlatform(PropertyLoader.loadProperty("browser.platform"));

		String username = PropertyLoader.loadProperty("user.username");
		String password = PropertyLoader.loadProperty("user.password");
		
		driver = WebDriverFactory.getInstance(gridHubUrl, browser, username,
				password);
		driver = new FirefoxDriver();  
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		
		userHelper = new UserHelper1(this);
	    filmHelper = new FilmHelper1(this);
	    navHelper = new NavigationHelper1(this);

		getNavigationHelper().openMainPage();
		
    }

	@Override
	public UserHelper getUserHelper() {
		return userHelper;
	}

	@Override
	public FilmHelper getFilmHelper() {
		return filmHelper;
	}
	
	@Override
	public NavigationHelper getNavigationHelper() {
		return navHelper;
	}	
	
    protected WebDriver getWebDriver(){
    	return driver;
    }
    
    protected String getBaseUrl(){
    	return baseUrl;
    }
    @Override
    public void stop(){
    	if (driver != null) {
		driver.quit();	
    }
    
 }
}
